﻿using System;
using System.Collections.Generic;

using System.Text;
using System.Collections;
using System.Windows.Documents;
using System.Windows.Media;
using System.Windows;
using System.Windows.Controls.Primitives;
using System.Windows.Controls;

namespace Bixas.Tangibilis.Controls.Primitives
{
  internal class TouchRepeatButtonAdapter : TouchButtonBaseAdapter<TouchRepeatButton>
  {

      public TouchRepeatButtonAdapter(TouchRepeatButton elementAdapted)
          : base(elementAdapted)
      { }

      public override void OnTouchCursorUp(System.Windows.RoutedEventArgs e)
      { 
          base.OnTouchCursorUp(e);
          if (TouchElement.ClickMode != ClickMode.Hover)
          {
              this.StopTimerHack();
          }
      }

      public override void OnTouchCursorDown(RoutedEventArgs e)
      {
          base.OnTouchCursorDown(e);
          if (base.IsTouchCursorPressed && (TouchElement.ClickMode != ClickMode.Hover))
          {
              StartTimerHack();
          }
      }

      private void StartTimerHack()
      {
          Phydeaux.Utilities.Dynamic<RepeatButton>.Instance.Procedure.Explicit.CreateDelegate("StartTimer").Invoke(this.TouchElement);
      }

      private void StopTimerHack()
      {
          Phydeaux.Utilities.Dynamic<RepeatButton>.Instance.Procedure.Explicit.CreateDelegate("StopTimer").Invoke(this.TouchElement);
      }
  }

}
